<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="流程名称">
              <a-input placeholder="名称" v-model="queryParam.name"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="流程Key">
              <a-input placeholder="Key" v-model="queryParam.key"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
            <a-button @click="() => queryParam = {}" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <s-table
      bordered
      ref="table"
      :alert="alert"
      :data="loadData"
      :columns="columns"
      :rowKey="record => record.taskId"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
    >
      <template v-slot:action="record">
        <span>
          <a-popconfirm title="是否办理该任务" @confirm="complete(record.taskId)" okText="是" cancelText="否">
            <a-icon slot="icon" type="question-circle-o" style="color: red" />
            <a href="javascript:" style="color: red">办理</a>
            <a-divider type="vertical" />
          </a-popconfirm>
        </span>
      </template>
    </s-table>
  </a-card>
</template>

<script>
import { TableMixin } from '@/mixins/TableMixin'
import { fetchList, complete } from '@/api/process/task'

export default {
  name: 'TaskList',
  components: {
  },
  mixins: [TableMixin],
  data () {
    return {
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => {
            return (
              <div>
                {index + 1}
              </div>
            )
          }
        }, {
          title: '名称',
          dataIndex: 'taskName'
        }, {
          title: '标题',
          dataIndex: 'title'
        }, {
          title: '时间',
          dataIndex: 'time'
        }, {
          title: 'taskId',
          dataIndex: 'taskId'
        }, {
          title: '操作',
          width: '200px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    /**
       * 发布
       */
    complete (taskId) {
      complete(taskId).then(res => {
        this.$message.info(res.msg)
        this.queryPage()
      })
    }
  }
}
</script>

<style scoped>

</style>
